<#import "/common/macro/standardLib.ftl" as std />

<#-- 标准列表宏定义 -->
<#macro standardList tableId dataUrl cols extensionPoint1 extensionPoint2 title formTitle deleteConfirm columns searchItems dataGridOptions newButtons formUrl script centerCustomAttrs showSearchMore=false checkSession=true iconCls="fa fa-tasks" showToolbar=true showCreateButton=model.showCreateButton showDeleteButton=model.showDeleteButton pagination=true>
	<#include "/common/macro/includeJavascript.ftl" />
	<#include "/common/macro/includeStylesheet.ftl" />
	<#if !dataUrl??>
		<#assign dataUrl = "${base}/${tableId}/getList" />
	</#if>
	<#if title??|| extensionPoint1?? || searchItems??>
		${extensionPoint1}
		<#if searchItems?? && searchItems != "">
			<div class="demoTable layui-form"  id="searchDiv">
				<fieldset class="layui-elem-field">
					<legend>搜索</legend>
					<div class="layui-inline">
						${searchItems}
					</div>
					<button class="layui-btn" data-type="reload" id="doSearch" style="float:right">
						<i class="layui-icon">&#xe615;</i>搜索
					</button>
				</filedset>
			</div>
		</#if>
	</#if>
	<#if showToolbar>
		<div id="toolbar_${model.clientId}" class="magic-toolbar">
			<div class="layui-btn-group" style="margin : 5px 20px;">
			<#if showCreateButton>
				<button class="layui-btn layui-create" style="margin-left:30px;" title="新建">
				  <i class="fa fa-plus"></i> 新建
				</button>
			</#if>
			<#if showDeleteButton>
				<button class="layui-btn layui-delete" style="margin-left:30px;" title="删除">
				  <i class="fa fa-eraser"></i> 删除
				</button>
			</#if>
			<button class="layui-btn layui-refresh" style="margin-left:30px;" title="刷新">
			  <i class="fa fa-refresh"></i> 刷新
			</button>
			<#if model.params.selectMode[0]!='true'>
				${newButtons}
			</#if>
			</div>
		</div>
	</#if>
	<table class="layui-hide" id="${tableId}"></table>
	<#if extensionPoint2??>
		${extensionPoint2}
	</#if>
	<#if deleteConfirm??>
		<input type="hidden" id="deleteConfirm_${model.clientId}" value="${deleteConfirm}" />
	</#if>
	<#include "/common/pageForm.ftl">
	<script>
		layui.use(['layer','table'], function(){
			addBtnCreateClickListener();
			addBtnDeleteClickListener();
			addBtnRefreshClickListener();
			addBtnSearchClickListener();
		});
		// 新建
		function addBtnCreateClickListener(){
			$(".layui-btn.layui-create").on("click",function (){
				layer.open({
		  		    type: 2,
					title:'${formTitle}',
		  		    content: '${formUrl}',
					area: ['90%', '90%'],
		            anim:2
			    });
			});
		}
		// 查询
		function addBtnSearchClickListener(){
			$("#doSearch").on("click",function (){
				var table = layui.table;
				// 获取filters
				var filters = $("#searchDiv").standardSearchAPI("getSearchFilter");
				table.reload('${tableId}',{where : {filters:JSON.stringify(filters)}});
			})
		}
		function addBtnRefreshClickListener(){
			$(".layui-btn.layui-refresh").on("click",function(){
				var table = layui.table;
				table.reload('${tableId}');
			})
		}
		function addBtnDeleteClickListener(){
			var $ = layui.$ , table = layui.table;
			$(".layui-btn.layui-delete").on("click",function (){
				var checks = table.checkStatus('${tableId}');
				if(checks.data.length < 1){
					layer.alert("请至少选择一行数据，再进行删除操作。", { icon: 5,shadeClose: true });
					return;
				}
				layer.confirm('真的删除选中行么', function(index){
			        layer.close(index);
			        //向服务端发送删除指令
			        mtdl.ajax({
			        	url : '${base}/${tableId}/delRecords',
			        	type : 'POST',
			        	data : {
			        		records : JSON.stringify(checks.data)
			        	},
			        	afterSuccess : function (){
					        // 刷新数据
					        table.reload('${tableId}');
			        	}
			        })
		        });
			});			
		}
		${script}
	</script>
</#macro>
